﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;

using Centrica.TaskManager.Data;

using Microsoft.Practices.Composite.Presentation.Commands;

namespace Centrica.TaskManager.Task
{
    public class TasksViewModel : INotifyPropertyChanged
    {
   
        public TasksViewModel()
        {
            this.EditTaskCommand = new DelegateCommand<Data.Task>(OnEditTask);
            this.DeleteTaskCommand = new DelegateCommand<Data.Task>(OnDeleteTask);
            this.AddTaskCommand = new DelegateCommand<Data.Task>(OnAddTask);

        }

        public ICommand EditTaskCommand { get; set; }
        public ICommand DeleteTaskCommand { get; set; }
        public ICommand AddTaskCommand { get; set; }

        public ObjectQuery<Data.Task> Tasks
        {
            get { return Data.ContextManager.Context.Task; }
        }

        protected virtual void OnEditTask(Data.Task task)
        {
            TaskViewModel taskViewModel = new TaskViewModel(task);

            TaskView taskView = new TaskView(taskViewModel);

            taskView.Show();
                   
        }

        protected virtual void OnDeleteTask(Data.Task task)
        {

            
        }

        protected virtual void OnAddTask(Data.Task task)
        {

            TaskViewModel taskViewModel = new TaskViewModel();

            TaskView taskView = new TaskView(taskViewModel);

            taskView.Show();
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));                        
            }
        }

        #endregion
    
    
    
    
    
    
    
    
    
    
    
    }
}
